home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr52 / ncclib.zip / NCCDEMO.ZIP / G_EVENT.PRG < prev    next >
Text File  |  1993-05-01  |  12KB  |  366 lines

  1. //═══════════════════════════════════════════════════════╕
  2. //  Program .....: G_Event                               │
  3. //  CopyRight ...: 1992 National Computer Consultants    │
  4. //                 All rights are reserved.              │
  5. //  Author ......: Greg Rice                             │
  6. //═══════════════════════════════════════════════════════╛
  7.  
  8. #include "g_event.ch"
  9. #include "g_menu.ch"
  10. #include "inkey.ch"
  11. #include "mouse.ch"
  12.  
  13. #define TO_SAVE  1
  14. #define TO_OPEN  2
  15.  
  16. //──────────────────────────┐
  17. //  Mouse Event Translation │
  18. //──────────────────────────┘
  19. Function MouseEvent()
  20.  
  21.     LOCAL Event  := 0                                   , ;
  22.           Mouse  := MouseSys()                          , ;
  23.           x      := Current_Window()                    , ;
  24.           Window := WinObj()                            , ;
  25.           nRow                                          , ;
  26.           nCol                                          , ;
  27.           xwin                                          , ;
  28.           i                                             , ;
  29.           p
  30.  
  31.  
  32.     nRow   := Mouse:Row
  33.     nCol   := Mouse:Column
  34.  
  35.     if Mouse:Button == RIGHT_BUTTON
  36.       Return( Event )
  37.     endif
  38.  
  39.     if ! Window_Active()
  40.       Return( Event )
  41.     endif
  42.  
  43.     Do Case
  44.       Case ( nRow == Window:TopRow - 3 .and. ;
  45.            (nCol >= Window:RightColumn -5 .and. ;
  46.             nCol <= Window:RightColumn -3 ))
  47.  
  48.            Event := ev_Up
  49.  
  50.       Case ( nRow == Window:TopRow - 3 .and. ;
  51.            (nCol >= Window:RightColumn -2 .and. ;
  52.             nCol <= Window:RightColumn ))
  53.  
  54.            Event := ev_Down
  55.  
  56.       Case ( nRow == Window:TopRow - 1 .and. ;
  57.             ( nCol >= Window:LeftColumn .and. ;
  58.               nCol <= Window:LeftColumn+1 ;
  59.             ) ;
  60.            )
  61.  
  62.            Event := ev_Left
  63.  
  64.       Case  ( nRow == Window:TopRow - 1 .and. ;
  65.            ( nCol >= Window:RightColumn -1 .and. ;
  66.             nCol <= Window:RightColumn ))
  67.  
  68.            Event := ev_Right
  69.  
  70.       Case ( nRow == Window:TopRow -4 .and. ;
  71.             ( nCol >= Window:LeftColumn -1 .and. ;
  72.               nCol <= Window:RightColumn +1 ))
  73.  
  74.            Event := ev_WindowMoveResize
  75.  
  76.       Case ( nRow == Window:BottomRow +1 .and. ;
  77.             ( nCol == Window:LeftColumn -1 .or. ;
  78.               nCol == Window:RightColumn +1 ;
  79.             ) ;
  80.            )
  81.           Event := ev_WindowMoveResize
  82.  
  83.       Case (  nRow >= Window:TopRow-4 .and. ;
  84.                     nRow <= Window:BottomRow+1 .and. ;
  85.                     nCol >= Window:LeftColumn-1 .and. ;
  86.                     nCol <= Window:RightColumn+1 ;
  87.            ) .and. Mouse:Button == BOTH_BUTTONS
  88.  
  89.           Event := ev_WindowZoom
  90.  
  91.       Case (  nRow >= Window:TopRow .and. ;
  92.                     nRow <= Window:BottomRow .and. ;
  93.                     nCol >= Window:LeftColumn .and. ;
  94.                     nCol <= Window:RightColumn ;
  95.            ) .and. Mouse:Button == LEFT_BUTTON
  96.  
  97.          if Window:CurrentRow > nRow
  98.            Window:Up(Window:CurrentRow - nRow)
  99.          else
  100.            Window:Down(nRow - Window:CurrentRow)
  101.          endif
  102.  
  103.       Otherwise
  104.  
  105.          xwin := x
  106.          p := len(win_stack())
  107.          for i = 1 to Len(windows())
  108.            if ! empty(WinFilename(xWin)).and.;
  109.               (  nRow >= WinObj(xWin):TopRow-4 .and. ;
  110.                  nRow <= WinObj(xWin):BottomRow+1 .and. ;
  111.                  nCol >= WinObj(xWin):LeftColumn-1 .and. ;
  112.                  nCol <= WinObj(xWin):RightColumn+1 ;
  113.               )
  114.               if xWin # x
  115.                 if ! empty(WinFilename(xWin))
  116.                   DeHighLightWindow(x)
  117.                 else
  118.                   loop
  119.                 endif
  120.                 HighLightWindow(xWin)
  121.               endif
  122.              exit
  123.            Endif
  124.  
  125.            if p # 1
  126.              xwin := win_stack()[--p]
  127.            endif
  128.  
  129.          next
  130.  
  131.     EndCase
  132.  
  133. Return( Event )
  134.  
  135.  
  136. //─────────────────────────────┐
  137. //  Menu Bar Event Translation │
  138. //─────────────────────────────┘
  139. Function MenuEvent( x )
  140.  
  141.     local Event := 0
  142.  
  143.     x := if( x == NIL, 0, x )
  144.  
  145.     Do Case
  146.  
  147.       Case x == ABOUT_ABOUT      ; Event := ev_About
  148.  
  149.       Case x == DATABASE_NEW     ; Event := ev_DataNew
  150.       Case x == DATABASE_OPEN    ; Event := ev_DataOpen
  151.       Case x == DATABASE_CLOSE   ; Event := ev_DataClose
  152.       Case x == STRUCTURE_DISPLAY ; Event := ev_DataStructure
  153.  
  154.       Case x == INDEX_OPEN       ; Event := ev_IndexOpen
  155.       Case x == INDEX_CLOSE      ; Event := ev_IndexClose
  156.       Case x == INDEX_REORDER    ; Event := ev_IndexReorder
  157.       Case x == VIEW_MODIFY      ; Event := ev_ViewModify
  158.  
  159.       Case x == SYS_EXIT         ; Event := ev_SysExit
  160.  
  161.       Case x == GO_REC           ; Event := ev_GoToRec
  162.       Case x == LOCA_REC         ; Event := ev_LocateRec
  163.       Case x == SEEK_REC         ; Event := ev_SeekRec
  164.  
  165.       Case x == WIN_NEXT         ; Event := ev_WindowNext
  166.       Case x == WIN_PREV         ; Event := ev_WindowPrev
  167.       Case x == WIN_MOVE         ; Event := ev_WindowMoveResize
  168.       Case x == WIN_ZOOM         ; Event := ev_WindowZoom
  169.       Case x == VIEW_VERT        ; Event := ev_WindowVertical
  170.       Case x == VIEW_HORI        ; Event := ev_WindowHorizontal
  171.  
  172.       Case x == HELP_GEN         ; Event := ev_GenHelp
  173.       Case x == HELP_WIN         ; Event := ev_WinHelp
  174.  
  175.     EndCase
  176.  
  177. Return( Event )
  178.  
  179.  
  180.  
  181. //────────────────────────────┐
  182. // KeyBoard Event Translation │
  183. //────────────────────────────┘
  184. Function KeyBoardEvent(x)
  185.  
  186.     LOCAL Event := 0, msColor := SetColor()
  187.  
  188.     x := if( x == NIL, 0, x )
  189.  
  190.     Do Case
  191.       Case x == K_TAB            ;    Event := ev_WindowNext
  192.       Case x == K_SH_TAB         ;    Event := ev_WindowPrev
  193.       Case x == K_UP             ;    Event := ev_Up
  194.       Case x == K_DOWN           ;    Event := ev_Down
  195.       Case x == K_LEFT           ;    Event := ev_Left
  196.       Case x == K_RIGHT          ;    Event := ev_Right
  197.       Case x == K_CTRL_LEFT      ;    Event := ev_Left
  198.       Case x == K_CTRL_RIGHT     ;    Event := ev_Right
  199.       Case x == K_HOME           ;    Event := ev_Home
  200.       Case x == K_END            ;    Event := ev_End
  201.       Case x == K_CTRL_PGUP      ;    Event := ev_GoTop
  202.       Case x == K_CTRL_PGDN      ;    Event := ev_GoBottom
  203.       Case x == K_PGUP           ;    Event := ev_PageUp
  204.       Case x == K_PGDN           ;    Event := ev_PageDown
  205.       Case x == K_CTRL_HOME      ;    Event := ev_PanHome
  206.       Case x == K_CTRL_END       ;    Event := ev_PanEnd
  207.       Case x == K_INS            ;    Event := ev_QuickInsertBlank
  208.       Case x == K_DEL            ;    Event := ev_QuickDelete
  209.  
  210.       Case x == K_ALT_1          ;    Event := x
  211.       Case x == K_ALT_2          ;    Event := x
  212.       Case x == K_ALT_3          ;    Event := x
  213.       Case x == K_ALT_4          ;    Event := x
  214.       Case x == K_ALT_5          ;    Event := x
  215.       Case x == K_ALT_6          ;    Event := x
  216.       Case x == K_ALT_7          ;    Event := x
  217.       Case x == K_ALT_8          ;    Event := x
  218.       Case x == K_ALT_9          ;    Event := x
  219.  
  220.       Case uppe(chr(x)) == 'F'   ;    Event := ev_DataOpen
  221.       Case uppe(chr(x)) == 'I'   ;    Event := ev_IndexOpen
  222.       Case uppe(chr(x)) == 'G'   ;    Event := ev_GoToRec
  223.       Case uppe(chr(x)) == 'L'   ;    Event := ev_LocateRec
  224.       Case uppe(chr(x)) == 'S'   ;    Event := ev_SeekRec
  225.  
  226.       Case x == K_ALT_F1         ;    Event := x
  227.  
  228.         SetColor("W+/R")
  229.         WinBox( 8, 15, 16, 64,,5, .t. )
  230.         @  9,18 say 'Garbage Collection..............:' + str(memory( -1  )) + "K"
  231.         @ 10,18 say 'Fixed Head......................:' + str(memory( 101 )) + "K"
  232.         @ 11,18 say 'Character Space.................:' + str(memory( 0 )) + "K"
  233.         @ 12,18 say 'Largest Block...................:' + str(memory( 1 )) + "K"
  234.         @ 13,18 say '................................:' + str(memory( 2 )) + "K"
  235.         @ 14,18 say 'EMS Available to VMM............:' + str(memory( 3 )) + "K"
  236.         @ 15,18 say 'EMS and Disk Available to VMM...:' + str(memory( 4 )) + "K"
  237.         inkey(0)
  238.         SetColor(msColor)
  239.         ShowBackGround()
  240.         ShowDeskTop()
  241.  
  242.     EndCase
  243.  
  244. Return( Event )
  245.  
  246.  
  247. //────────────────────┐
  248. //   Event Processing │
  249. //────────────────────┘
  250. Function EventProcess( Event )
  251.  
  252.     local Window := WinObj(), Mouse := MouseSys()
  253.  
  254.     Event := if( Event == NIL, 0, Event )
  255.  
  256.     Mouse:Hide()
  257.     Do Case
  258.       Case Event == ev_About ; GrayBar() ; g_about() ; UnGrayBar()
  259.  
  260.       Case Event == ev_DataOpen
  261.         DehighlightWindow()
  262.         GrayBar()
  263.         g_DataOpen()
  264.         UnGrayBar()
  265.         OpenWindow()
  266.  
  267.  
  268.       Case Event == ev_GenHelp .or. ;
  269.            Event == ev_WinHelp
  270.         GrayBar()
  271.         g_help( Event )
  272.         UnGrayBar()
  273.  
  274.     EndCase
  275.  
  276.     if ! Window_Active()
  277.       Mouse:Hide()
  278.       Return( Event )
  279.     endif
  280.  
  281.     Do Case
  282.       Case Event == ev_DataNew
  283.       Case Event == ev_DataClose         ;       g_Dataclose()
  284.  
  285.       Case Event == ev_WindowNext        ;       WinNext()
  286.       Case Event == ev_WindowPrev        ;       WinPrev()
  287.       Case Event == ev_WindowZoom        ;       WinZoom()
  288.  
  289.       Case Event == ev_WindowMoveResize
  290.         WinResize()
  291.  
  292.       Case Event == ev_ViewModify
  293.         GrayBar()
  294.         g_ViewCreate()
  295.         UnGrayBar()
  296.         OpenWindow()
  297.  
  298.       Case Event == ev_WindowVertical    ;  g_Record()
  299.       Case Event == ev_WindowHorizontal  ;  g_Browse()
  300.  
  301.  
  302.       Case Event == ev_Left
  303.         if Window:UserSlot[2] == NIL
  304.           Window:Left()
  305.         endif
  306.  
  307.       Case Event == ev_Right     
  308.         if Window:UserSlot[2] == NIL
  309.           Window:Right()
  310.         endif
  311.  
  312.       Case Event == ev_PanHome
  313.         if Window:UserSlot[2] == NIL
  314.           Window:PanHome()
  315.         endif
  316.  
  317.       Case Event == ev_PanEnd
  318.         if Window:UserSlot[2] == NIL
  319.           Window:PanEnd()
  320.         endif
  321.  
  322.       Case Event == ev_Up        ;  Window:Up()
  323.       Case Event == ev_Down      ;  Window:Down()
  324.       Case Event == ev_Home      ;  Window:Home()
  325.       Case Event == ev_End       ;  Window:End()
  326.       Case Event == ev_GoTop     ;  Window:GoTop()
  327.       Case Event == ev_GoBottom  ;  Window:GoBottom()
  328.       Case Event == ev_PageUp    ;  Window:PageUp()
  329.       Case Event == ev_PageDown  ;  Window:PageDown()
  330.  
  331.       Case Event == K_ALT_1    ;  GotoWin(1)
  332.       Case Event == K_ALT_2    ;  GotoWin(2)
  333.       Case Event == K_ALT_3    ;  GotoWin(3)
  334.       Case Event == K_ALT_4    ;  GotoWin(4)
  335.       Case Event == K_ALT_5    ;  GotoWin(5)
  336.       Case Event == K_ALT_6    ;  GotoWin(6)
  337.       Case Event == K_ALT_7    ;  GotoWin(7)
  338.       Case Event == K_ALT_8    ;  GotoWin(8)
  339.       Case Event == K_ALT_9    ;  GotoWin(9)
  340.  
  341.       Case Event == ev_IndexOpen          ; GrayBar() ; g_indexopen()   ; UnGrayBar()
  342.       Case Event == ev_IndexReorder       ; GrayBar() ; g_indexorder()  ; UnGrayBar()
  343.       Case Event == ev_IndexClose         ; GrayBar() ; g_indexClose()  ; UnGrayBar()
  344.       Case Event == ev_GoToRec            ; GrayBar() ; g_Goto()        ; UnGrayBar()
  345.       Case Event == ev_LocateRec          ; GrayBar() ; g_Locate()      ; UnGrayBar()
  346.       Case Event == ev_SeekRec            ; GrayBar() ; g_seek()        ; UnGrayBar()
  347.  
  348.  
  349.     EndCase
  350.  
  351.     Mouse:Show()
  352.     Window_Active( ! Empty(alias()) )
  353.  
  354. Return( NIL )
  355.  
  356.  
  357. static function GotoWin( x )
  358.  
  359.     if ! Empty(Winfilename(x))
  360.       DeHighLightWindow()
  361.       Current_Window(x)
  362.       HighLightWindow()
  363.     endif
  364.  
  365. Return( NIL )
  366.